﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Speech.Synthesis;
using NicoView.Model.Speech;
using NicoView.Model.Share.Speech;
using NicoView.Model.Share.Speech.Learn;

namespace NicoView.Model.Platform.Speachers.Sapi
{
    public sealed class SapiSpeacherProvider:SpeacherProviderBase
    {
        private SapiSpeacherProvider(InstalledVoice voice)
        {
            _voice = voice;

            Group = "Sapi";
        }

        private InstalledVoice _voice;



        public override ISpeacher GetInstance()
        {
            if (Speacher == null) Speacher = new SapiSpeacher(_voice.VoiceInfo.Name, RegexLearnDictinary,LearnDictinary);
            return Speacher;
        }

        private static RegexLearnDictionary RegexLearnDictinary { get; set; }

        private static LearnDictionary LearnDictinary { get; set; }

        public static ICollection<SpeacherProviderBase> GetInstalledProvider(RegexLearnDictionary regexDic,LearnDictionary dic)
        {
            if (RegexLearnDictinary == null) RegexLearnDictinary = regexDic;
            if (LearnDictinary == null) LearnDictinary = dic;
            using (var speechSynthesizer = new SpeechSynthesizer())
            {
                var list = new List<SpeacherProviderBase>();
                var baseList = speechSynthesizer.GetInstalledVoices();
                foreach (var voice in baseList)
                {
                    
                    if(voice.VoiceInfo.Culture.Name == "ja-JP") list.Add(new SapiSpeacherProvider(voice));
                }
                return list;
            }

        }

        public override string Name
        {
            get { return _voice.VoiceInfo.Name; }
        }



        public override SpeacherProviderBase Copy()
        {
            return new SapiSpeacherProvider(_voice);
        }
    }
}
